<template>
  <div class="_wz_cent_main _wz_hiddenTroubleReport">
    <Card dis-hover :bordered="true" style="margin:0 0 10px;">
      <p slot="title">搜索</p>
      <div slot="extra">
        <Button type="info" size="small" v-if="!searchType" @click="searchType = true" icon="ios-arrow-down">更多</Button>
        <Button type="info" size="small" v-else @click="searchType = false" icon="ios-arrow-up">收起</Button>
      </div>
      <Form :model="formDataSearch" label-position="right" :label-width="80" inline>
        <FormItem label="排查位置">
          <i-input v-model="formDataSearch.riskPositionName" placeholder="请填写排查位置" clearable />
        </FormItem>
        <FormItem label="处理状态">
          <i-select v-model="formDataSearch.dangerState" filterable placeholder="请选择处理状态" clearable>
            <Option value="0">处理中</Option>
            <Option value="1">已处理</Option>
          </i-select>
        </FormItem>
        <FormItem label="隐患等级" v-if="searchType">
          <i-select v-model="formDataSearch.riskDangerCheckResultState" filterable placeholder="请选择隐患等级" clearable>
            <Option value="0">无风险</Option>
            <Option value="1">一般隐患</Option>
            <Option value="2">重大隐患</Option>
          </i-select>
        </FormItem>
        <FormItem label="运输企业" v-if="searchType">
          <i-select v-model="formDataSearch.deptUuid" filterable placeholder="请选择运输企业" clearable>
            <Option v-for="item in subDeptList" :value="item.uuid" :key="item.uuid">{{ item.deptName }}</Option>
          </i-select>
        </FormItem>
        <FormItem>
          <Button type="primary" @click="searchSubmit">搜索</Button>
        </FormItem>
      </Form>
    </Card>
    <Card dis-hover :bordered="true">
      <p slot="title">列表</p>
      <p slot="extra">
        <Button type="primary" @click="formOperationAdd = true;">添加</Button>
      </p>
      <wzTbale ref="wzTbale" :tableData="tableData"></wzTbale>
    </Card>


    <Drawer :title="formTitle" v-model="operationProcessType" width="1100" :mask-closable="false" :draggable="true" :styles="formOperationStyles">
      <operationProcess v-if="operationProcessType" @closeFun="closeFun" :selectData="selectData"></operationProcess>
    </Drawer>

    <Drawer title="添加" v-model="formOperationAdd" width="1100" :mask-closable="false" :draggable="true" :styles="formOperationStyles">
      <hiddenTroubleReportAdd v-if="formOperationAdd" @closeFun="closeFun"></hiddenTroubleReportAdd>
    </Drawer>


    <Drawer title="详情" v-model="formOperation" width="1100" :mask-closable="false" :draggable="true">
      <hiddenDetails v-if="formOperation" :selectData="selectData"></hiddenDetails>
    </Drawer>

    <Drawer title="操作记录" v-model="operationRecordsType" width="700" :mask-closable="false" :draggable="true">
      <operationRecords v-if="operationRecordsType" :selectData="selectData"></operationRecords>
    </Drawer>

  </div>
</template>
<script>


import wzTbale from "../../components/table/table";
import operationProcess from "./operationProcess";
import hiddenDetails from "./hiddenDetails";// hiddenDetails  隐患详情
import operationRecords from "./operationRecords";//操作记录
import hiddenTroubleReportAdd from "./hiddenTroubleReportAdd";//上报添加

export default {
  components: {
    wzTbale,//列表
    operationProcess,//操作 处理
    hiddenDetails,//隐患详情
    operationRecords,
    hiddenTroubleReportAdd,//上报添加
  },
  data() {
    return {
      formOperationAdd:false,
      operationRecordsType:false,//操作记录
      formOperation:false,
      formTitle:'',
      operationProcessType:false,//操作处理
      formOperationStyles: {//表单左侧移出css
        height: 'calc(100% - 55px)',
        overflow: 'auto',
        paddingBottom: '53px',
        position: 'static'
      },
      searchType:false,//搜索条件
      subDeptList: [],//运输企业
      formDataSearch: {riskInspectItemProcess:1},//搜索表单数据
      selectData: {},
      tableData: {
        url: this.apiUrl.riskInspectRiskInspectItemPageList,//请求地址
        method: 'post',//请求方式
        where: {riskInspectItemProcess:1},//搜索条件
        height: 'auto',//表格高度 auto
        page: true,//分页是否使用
        columns: [//表头数据
          {type: 'index', width: 70, align: 'center', title: '序号'},
          {title: '隐患排查', minWidth: 140, key: 'riskInspectItemName'},
          {title: '处理流程', minWidth: 140, key: 'riskInspectItemProcess', render: (h, params) => {
              //0：未排查，1：已上报，2：已核查，3：已整改，4：已验收，5：已完成
              var color = '', test = '';
              if (params.row.riskInspectItemProcess == 1) {
                color = 'warning', test = '已上报';
              } else if (params.row.riskInspectItemProcess == 2){
                color = 'warning', test = '已核查';
              }  else if (params.row.riskInspectItemProcess == 3){
                color = 'warning', test = '已整改';
              } else if (params.row.riskInspectItemProcess == 4){
                color = 'success', test = '已验收';
              }
              return h('Tag', {props: {type: 'dot',color: color}}, test);
            }
          },

          // {title: '隐患部位', minWidth: 140, key: 'riskPositionName'},
          // {title: '隐患项目', minWidth: 140, key: 'riskPositionItemName'},
          {title: '隐患等级', minWidth: 140, key: 'riskInspectItemLv', render: (h, params) => {
              //0：不是隐患，1：一般隐患，2：重大隐患
              var color = '', test = '';
              if (params.row.riskInspectItemLv == 0) {
                color = 'success', test = '无隐患';
              } else if (params.row.riskInspectItemLv == 1) {
                color = 'warning', test = '一般隐患';
              } else if (params.row.riskInspectItemLv == 2){
                color = 'error', test = '重大隐患';
              } else{
                color = 'error', test = '未排查';
              }
              return h('Tag', {props: {type: 'dot',color: color}}, test);
            }
          },
          {title: '排查人员', minWidth: 120, key: 'riskInspectItemUserName'},
          {title: '隐患描述', minWidth: 160, key: 'riskInspectItemContext'},
          {title: '排查时间', key: 'riskInspectItemTime', minWidth: 180},
          {title: '运输企业', minWidth: 260, key: 'deptName'},
          {title: '完成状态', minWidth: 140,fixed: 'right', key: 'riskInspectItemFinish', render: (h, params) => {
              //（0：未完成，1：已完成）
              var color = '', test = '';
              if (params.row.riskInspectItemFinish == 0) {
                color = 'error', test = '未完成';
              } else if (params.row.riskInspectItemFinish == 1){
                color = 'primary', test = '已完成';
              }
              return h('Tag', {props: {type: 'dot',color: color}}, test);
            }
          },
          {
            title: '操作', fixed: 'right', width: 120,
            render: (h, params) => {
              var operationButtons = [];
              //查看
              operationButtons.push(
                h('span', {style: {"color": "#2d8cf0", "cursor": "pointer"},
                  on: {
                    click: () => {
                      this.selectData = JSON.parse(JSON.stringify(params.row));
                      this.formOperation = true;
                    }
                  }
                }, "查看")
              )

              if(params.row.riskInspectItemCheckState == -1){
                operationButtons.push(h('Divider', {props: {type: 'vertical',}}, ''))
                //核查
                operationButtons.push(
                  h('span', {style: {"color": "#2d8cf0", "cursor": "pointer"},
                    on: {
                      click: () => {
                        this.formTitle = '隐患上报';
                        this.selectData = JSON.parse(JSON.stringify(params.row));
                        this.operationProcessType = true;
                      }
                    }
                  }, "上报")
                )
              }else{
                operationButtons.push(h('Divider', {props: {type: 'vertical',}}, ''))
                //记录
                operationButtons.push(
                  h('span', {style: {"color": "#2d8cf0", "cursor": "pointer"},
                    on: {
                      click: () => {
                        this.selectData = JSON.parse(JSON.stringify(params.row));
                        this.operationRecordsType = true;
                      }
                    }
                  }, "记录")
                )
              }
              return operationButtons;
            }
          },
        ],
        format: {//返回数据格式
          list: ['data'],//数据list
          count: ['count'],//数据总量
        },
      },

    }
  },
  beforeCreate() {//beforeCreate创建前状态

  },
  created() {//created创建完毕状态
  },
  beforeMount() {//beforeMount挂载前状态   DOM 元素然后塞入页面的过程

  },
  mounted() {//mounted 挂载结束状态
    var that = this;

    //运输企业
    that.axios.post(that.apiUrl.coreDeptCoreDeptList,{}).then(res => {
      if (!!res) {
        that.subDeptList = res.data.data;
      }
    }).catch(err => {
      console.log("失败", err)
    })
  },
  methods: {//执行的方法
    searchSubmit() {//搜索
      this.tableData.where = JSON.parse(JSON.stringify(this.formDataSearch));
      this.$refs.wzTbale.tableLoadData(true);
    },
    //添加修改触发后关闭刷新
    closeFun(data) {
      var that = this;
      if (data) {//添加修改 刷新表单
        that.$refs.wzTbale.tableLoadData();
      }
      that.operationProcessType = false;
      that.formOperationAdd = false;
    },
  },
  watch: {//监听

  },
  beforeUpdate() {//beforeUpdate 更新前状态

  },
  updated() {//updated 更新完成状态

  },
  beforeDestroy() {//beforeDestroy 销毁前状态

  },
  destroyed() {//destroyed 销毁完成状态

  }
}
</script>
<style lang="less">
._wz_hiddenTroubleReport {
  display: flex;
  flex-direction: column;
}
</style>
